#include <iostream>
#include <vector>
using namespace std;
int zs(int n)
{
    int i;
    for (i = 2; i < n; i++){
        if (n % i == 0)
            break;
    }
    if (i < n)
        return 0;
    else
        return 1;
}

int maxZsSum01(const vector<int> &shu)
{
    int maxSum = 0;
    for (int i = 0; i < shu.size(); i++) {
        for (int j = i; j < shu.size(); j++) {
            int sum = 0;
            for (int k = i; k <= j; k++) {
                sum += shu[k];
            }
            if (zs(j - i + 1) && sum > maxSum) {
                maxSum = sum;
            }
        }
    }
    return maxSum;
}

int maxZsSum02(const vector<int>& shu)
{
    int n = shu.size();
    vector<int> prefixSum(n + 1, 0);
    for (int i = 0; i < n; i++) {
        prefixSum[i + 1] = prefixSum[i] + shu[i];
    }
    int maxSum = 0;
    for (int len = 2; len <= n; len++) {
        for (int start = 0; start + len <= n; start++) {
            int end = start + len;
            if (zs(len) && (prefixSum[end] - prefixSum[start] > maxSum)) {
                maxSum = prefixSum[end] - prefixSum[start];
            }
        }
    }
    return maxSum;
}

int main6()
{
    int size;
    cin >> size;
    vector<int> shu(size);
    for (int i = 0; i < size; i++)
        cin >> shu[i];
    
    cout << maxZsSum02(shu) << endl;
    return 0;
}

